package morenoapp.action;

import morenoapp.action.*;
import morenoapp.*;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action;
import javax.swing.JOptionPane;
import morenoapp.action.MorenoActionException;
import morenoapp.action.resources.ActionsResourcesHolder;
import morenoapp.resources.ResourcesHolder;
import morenoapp.util.I18N;

/**
 *
 * @author root
 */
public class MorenoActionProxy implements javax.swing.Action {
    static final Logger log = Logger.getLogger(MorenoActionProxy.class.getName());
    String name;
    javax.swing.Action delegate;
    public MorenoActionProxy(String name, Action delegate) {
        this.name = name;
        this.delegate = delegate;
    }

    public void actionPerformed(ActionEvent e) {
        log.info("Start : "+name);
        try {
            delegate.actionPerformed(e);
            log.info("Done  : "+name);
        } catch(MorenoActionException ex){
            log.log(Level.INFO, ex.getMessage(), ex);
            JOptionPane.showMessageDialog(MorenoApp.getApplication().getMainFrame(),
                    ex.getMessage(),
                    I18N.get("action.exception_handled")+delegate.getValue("text"),
                    JOptionPane.WARNING_MESSAGE,
                    ActionsResourcesHolder.ICON_MESSAGE_WARNING_MED);
        } catch(Exception ex){
            log.log(Level.SEVERE, null,ex);
        }
    }

    public void setEnabled(boolean b) {
        delegate.setEnabled(b);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        delegate.removePropertyChangeListener(listener);
    }

    public void putValue(String key, Object value) {
        delegate.putValue(key, value);
    }

    public boolean isEnabled() {
        return delegate.isEnabled();
    }

    public Object getValue(String key) {
        return delegate.getValue(key);
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        delegate.addPropertyChangeListener(listener);
    }
};
